package MyPackage;
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		
System.out.println("MyCMD start...");
Scanner inp=new Scanner(System.in);

	String dir;
	
	System.out.println("\nExercise 2\n**Print tree of directory**\nInput directory:");
	dir=inp.nextLine();
	printTreeDir(dir);
			
System.out.println("\nMyCMD stop.");
	}
	
		public static void printTreeDir(String dir){
		File f=new File(dir);
		if(!f.exists()){
			System.out.println("Not found directory "+f.toString());
		}
		else{
			System.out.println(dir);
			printTree(dir,0);
		}
	}
	public static void printNameDir(String dir,String dirList, int y){
		File f1=new File(dir+File.separator+dirList);
		if(!f1.isFile()){
			for(int j=0; j<y;j++ )System.out.print("  ");
			System.out.println("+ "+dirList);
			}
		}
	
		
	public static void printTree(String dir,int y){
		// y - level inserted. Start from 0. Increase.
		File f=new File(dir);
		String[] dirList=f.list();
		for(int i=0;i<dirList.length;i++){
			printNameDir(dir,dirList[i],y);
			// if dirList[i] is directory then call printTree for dirList[i]
			String absDir=dir+File.separator+dirList[i];
			File f1=new File(absDir);
			if(!f1.isFile()) printTree(absDir,y+1);
			}
	}
	
}	



